//ColMajor.java

/*
 * 本类实现列主序的方阵遍历方式。
 */
public class ColMajor extends SquareTraversal{
    public ColMajor(int size) {
        // 在这里添加代码：
        initiate(size);
    }

    @Override public SquarePoint getInitPoint() {
        // 在这里添加代码：
        return new SquarePoint(0,0);
    }

    @Override public SquarePoint getNext() {
        // 在这里添加代码：
        SquarePoint currPoint = currentPath.get(currentPath.size() - 1);
        int currRow = currPoint.getRow();
        int currCol = currPoint.getCol();

        int nextRow = 0;
        int nextCol = 0;

        if (currRow < size - 1) {
            nextRow = currRow+1;
            nextCol = currCol;
        } else {
            if (currCol == size - 1) {
                return null;
            } else {
                nextRow = 0;
                nextCol = currCol + 1;
            }
        }

        SquarePoint nextPoint = new SquarePoint(nextRow, nextCol);
        return nextPoint;
    }
}
